/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.biz.manager.transaction.impl;

import java.util.Date;

import org.grayrabbit.pay.core.biz.manager.transaction.TradeManager;
import org.grayrabbit.pay.core.model.entity.transaction.Trade;
import org.grayrabbit.pay.core.model.enums.TradeEnum;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.results.GenericsResult;
import org.grayrabbit.pay.core.model.results.PayResult;
import org.grayrabbit.pay.core.service.transaction.TradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 
 * 
 * @author liyd
 * @version $Id: TradeManagerImpl.java, v 0.1 Thu May 31 14:50:37 CST 2012 liyd Exp $
 */
@Component
public class TradeManagerImpl implements TradeManager {

    @Autowired
    private TradeService              tradeService;

    /**
     * 查询业务列表
     * 
     * @param district
     * @return
     */
    public GenericsResult<PageList<Trade>> queryPageList(Trade trade, Date startDate, Date endDate) {

        GenericsResult<PageList<Trade>> result = new GenericsResult<PageList<Trade>>(true);
        PageList<Trade> list = tradeService.queryPageList(trade, startDate, endDate);
        for (Trade atrade : list) {
            atrade.setStatusEnum(TradeEnum.getTradeEnum(atrade.getTradeStatus()));
        }
        result.setResultData(list);

        return result;
    }

    public GenericsResult<PageList<Trade>> queryPageList(Trade trade) {

        GenericsResult<PageList<Trade>> result = new GenericsResult<PageList<Trade>>(true);
        PageList<Trade> list = tradeService.queryPageList(trade);
        for (Trade atrade : list) {
            atrade.setStatusEnum(TradeEnum.getTradeEnum(atrade.getTradeStatus()));
        }
        result.setResultData(list);

        return result;
    }

    /**
     * 根据Id得到实体对象
     * 
     * @param id
     * @return
     */
    public GenericsResult<Trade> getById(Long id) {

        GenericsResult<Trade> result = new GenericsResult<Trade>(true);

        result.setResultData(tradeService.getById(id));

        return result;

    }

    /**
     * 根据id批量删除
     * 
     * @param idArray
     * @return
     */
    public PayResult deleteBatchById(Long[] idArray) {

        PayResult result = new PayResult(true);

        tradeService.deleteBatchById(idArray);

        return result;
    }

    /**
     * 添加一个对象
     * 
     * @param trade
     * @return
     */
    public GenericsResult<Trade> insert(Trade trade) {

        GenericsResult<Trade> result = new GenericsResult<Trade>(true);

        tradeService.insert(trade);

        return result;

    }


}
